﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace GGJ.Sprites
{
    class FlyCatcher : Ennemy
    {
        private int tileWidth = 56;
        private int tileHeight = 300;

        public FlyCatcher(Texture2D texture, int x, int y) : base(texture)
        {
            destination = new Rectangle(
                x,
                y,
                tileWidth,
                tileHeight);
        }

        public override void Update(GameTime gameTime, Flies flies,KilledFlies killedFlies,float speed,bool isSlowMotion)
        {

            destination.X -= (int)speed;

            Rectangle hitBox = new Rectangle(destination.X + tileWidth / 2, destination.Y,
                tileWidth / 2, tileHeight);

            Fly fly;

            for (int i = 0; i < flies.Count(); i++)
            {
                fly = flies.GetFly(i);

                if (fly != null)
                    if (hitBox.Intersects(fly.GetDestination()))
                    {
                        Program.crushing.Play();

                        flies.removeFly(i);
                        fly.isDead = true;
                        fly.causeOfDeath = FliesMovement.Stuck;
                        killedFlies.AddFly(fly);
                    }
                       
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            Rectangle source;

            source = new Rectangle(0,
                0,
                tileWidth,
                tileHeight);

            spriteBatch.Draw(texture, destination, source, Color.White);
        }
    }
}
